package cn.itcast.controller;

import cn.itcast.bean.Admin;
import cn.itcast.service.AdminService;
import cn.itcast.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin")
@CrossOrigin(maxAge = 3600)//允许跨域
public class AdminController {

    //依赖注入
    @Autowired
    AdminService adminService;

//    @RequestMapping("list")
//    public List<Admin>getAdminList(){
//        List<Admin>list=adminService.list();
//        return list;
//    }

    @GetMapping("list")
    public Result getlist(){
        List<Admin> list =adminService.list();
        return Result.success(list);
    }
    @PostMapping
    public Result add(@RequestBody Admin tadmin){
        adminService.save(tadmin);
        Admin saveadmin=adminService.getById(tadmin.getId());
        return Result.success("保存成功",saveadmin);
    }
}